<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="/css/css.css" rel="stylesheet" type="text/css" />
</head>
<body class="bj">
<section>
    <div class="head">
        <p class="head_top"></p>
        <div class="head_btn">
            <span class="head_1">文字直播间</span>
            <span class="head_2">注册账号</span>
            <div class="head_right">
                <span>我已注册，现在就</span>
                <a href="/login"><span>登陆</span></a>
            </div>
        </div>
    </div>
    <div class="body">
        <div class="biaodan">
            <ul>
                <li>
                    <span>请输入手机号码</span>
                    <input id="mobile" type="text" />
                </li>
                <li>
                    <span>短信验证码</span>
                    <input id="code" type="text" class="duanxin">
                    <a id="getcode" href="javascript:void(0);" class="change-code">获取验证码</a>
                </li>
            </ul>
        </div>
        <div class="checkbox">
            <label>
                <input type="checkbox" class="checkbox1" id="agree" />
                <span>我已阅读，并接受《用户服务协议》</span>
            </label>
        </div>
        <div class="buttom">
            <a id="submit">提交</a>
        </div>
    </div>
</section>
<script type="text/javascript" src="/js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/layer/2.1/layer.js"></script>
<script type="text/javascript">
    $(function () {
        $("#getcode").click(function () {
            var mobile = $("#mobile");
            var reg = /^1([3|5|7|8])\d{9}$/;
            if (reg.test(mobile.val())){
                $.ajax({
                    type: 'post', dataType: 'json', cache: false,
                    url: '/get_code',
                    data: {'mobile': mobile.val()},
                    success: function (data) {
                        if (data.status == 0) {
                            layer.msg(data.info, {icon: 6});
                        }else{
                            layer.msg(data.info, {icon: 2});
                        }
                    }
                });
            }else{
                layer.msg('手机号不合法', {icon: 5, time: 1000}, function () {
                    mobile.val('').focus();
                });
            }
        });
        $("#submit").click(function () {
            var mobile = $("#mobile");
            var reg = /^1([3|5|7|8])\d{9}$/;
            if (reg.test(mobile.val())){
                var code = $("#code");
                if (code.val() != '') {
                    if ($("#agree").is(":checked")) {
                        $.ajax({
                            type: 'post', dataType: 'json', cache: false,
                            url: '/do_reg',
                            data: {'mobile': mobile.val(), 'code': code.val()},
                            success: function (data) {
                                if (data.status == 0){
                                    window.location.href = '/reg_info';
                                }else{
                                    layer.msg(data.info, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    }else{
                        layer.msg('请阅读用户服务协议并同意', {icon: 2});
                        return false;
                    }
                }else{
                    layer.msg('请输入验证码', {icon: 5, time: 1000}, function () {code.focus();});
                    return false;
                }
            }else{
                layer.msg('手机号不合法', {icon: 5, time: 1000}, function () {mobile.focus();});
                return false;
            }
        });
    });
</script>
</body>
</html>